package com.lagou.homework3;

/**
 *  编写程序，循环接收用户从键盘输入多个字符串
 *  直到输入“end”时循环结束，并将所有已输
 *  入的字符串按字典顺序倒序录入到项目下abc.txt中
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class StringTest {

    public static void main(String[] args) {

        List<String> list = new ArrayList<String>();
        BufferedReader br = null;
        Scanner sc = new Scanner(System.in);
        try {

            System.out.println("请输入多个字符串，直到输入end结束");
            //String str1 = sc.next();
            br = new BufferedReader(new InputStreamReader(System.in));
            String line = null;
            while ((line = br.readLine()) != null) {
                if ("end".equals(line)) {
                    break;
                }
                list.add(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (null != br) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        Collections.sort(list, Collections.reverseOrder());
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    }
}
